package com.gdut.simple.presenter.user;

import com.gdut.simple.common.RequestCallback;
import com.gdut.simple.contract.FavoritesContract;
import com.gdut.simple.data.entity.Favorites;
import com.gdut.simple.model.IFavoritesModel;
import com.gdut.simple.model.impl.FavoritesModelImpl;

import java.util.List;

public class FavoritesPresenter implements FavoritesContract.Presenter {

    private FavoritesContract.View mFavoritesView;
    private IFavoritesModel mFavoritesModel;

    public FavoritesPresenter(FavoritesContract.View view) {
        this.mFavoritesView = view;
        mFavoritesModel = new FavoritesModelImpl();
        this.mFavoritesView.setPresenter(this);
    }

    @Override
    public void loadData() {
        if (mFavoritesView.getUser() == null) {
            return;
        }
        mFavoritesView.showRefreshProgress();
        mFavoritesModel.loadData(mFavoritesView.getUser(), mFavoritesView.getTypes(), new RequestCallback<List<List<Favorites>>>() {
            @Override
            public void onSuccess(List<List<Favorites>> lists) {
                mFavoritesView.hideRefreshProgress();
                mFavoritesView.getItemList().clear();
                mFavoritesView.getItemList().addAll(lists);
                mFavoritesView.refreshList();
            }

            @Override
            public void onFailure(String message) {
                mFavoritesView.hideRefreshProgress();
                mFavoritesView.showMessage(message);
            }
        });
    }
}
